<?php

require_once 'model/army.php';
require_once 'model/magic.php';

class hero
{
    public $race;
    public $level = 1;
    public $defatt_level = 0;
    public $magic_level = 0;
    public $harrang_goodpay_level = 0;
    public $tactician_level = 0;
    public $cavalry_level = 0;
    public $archer_level = 0;
    public $infantry_level = 0;

    public $army;
    public $magic = array();

    public function __construct()
    {
        $this->army = new army();
    }

    public function get_level_bonus()
    {
        return $this->defatt_level * 0.005;
    }

    public function get_harrang_goodpay_bonus()
    {
        return $this->harrang_goodpay_level * 5;
    }

    public function get_tactician_bonus()
    {
        return $this->tactician_level * 0.01;
    }

    public function get_unit_type_bonus($type)
    {
        if ($type == ARCHER)
        {
            return $this->archer_level * 0.03;
        }
        if ($type == CAVALRY)
        {
            return $this->cavalry_level * 0.03;
        }
        if ($type == INFANTRY)
        {
            return $this->infantry_level * 0.03;
        }
    }

    public function get_base_xp($opponent)
    {
        return $opponent->army->get_xp();
    }

    public function get_raw_power()
    {
        return $this->army->get_power();
    }

    public function get_honnor_ratio($opponent)
    {
        return ($this->get_raw_power() / $opponent->get_raw_power());
    }

    public function get_final_xp($opponent)
    {
        return $this->get_base_xp() * ($this->get_honnor_ratio() + 1);
    }

    public function is_dead()
    {
        return $this->army->is_empty();
    }

    public function add_magic($turn, $magic)
    {
        $this->magic[] = new magic($turn, $magic);
    }

    public function magic_begin_hook($turn, army &$opponent_army, hero &$opponent_hero)
    {
        foreach ($this->magic as $magic)
        {
            $magic->begin_hook($turn, $this->army, $opponent_army, $this, $opponent_hero);
        }
    }
}

?>
